<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Auth;
class Banner extends Model {
    /**
     * 轮播表
     * @var string
     */
    protected $table = 'banner';
    protected $fillable = [
        'id',
        'banner_title',
        'banner_img',
        'create_time',
        'created_at',
        'updated_at'
    ];

    /**
     * 添加轮播
     * @param array $data
     * @return int
     */
    public function add_banner($data = array())
    {
        //insertGetId
        return $this->insert($data);
    }

    /**
     * 获取所有数据
     */
    public function get_banner($pages = true)
    {
        if($pages){
            $bannerData = $this->where('type',1)->orderBy('id','desc')->paginate(15);
        } else {
            $bannerData = $this->where('type',1)->select('id','banner_img')->orderBy('id','desc')->get()->toArray();
        }
        if($bannerData){
            return $bannerData;
        }else {
            return false;
        }
    }


    /**
     * 查询单条
     */
    public function find_banner($id)
    {
        $findData = $this->where('id',$id)->first();
        if($findData){
            return $findData;
        } else {
            return false;
        }
    }

    /**
     * 修改轮播
     */
    public function edit_banner($data=array(),$id)
    {
        $res = $this->where('id',$id)->update($data);
        if($res){
            return true;
        } else {
            return false;
        }
    }

    /**
     * 删除轮播
     */
    public function delete_banner($id)
    {
        $res = $this->where('id',$id)->delete();
        if($res){
            return true;
        } else {
            return false;
        }
    }



}
